package chalmers.game.subterranean.util;

import chalmers.game.subterranean.util.options.WorldValues;
import lombok.Getter;

/**
 * A holder for an exact position of an object, depthlevel coupled with the coordinates counted in
 * square parts with origo in the upper left corner.
 * 
 * @author Alex Evert
 */
public class ExactPosition {
  @Getter
  final double x;
  @Getter
  final double y;
  @Getter
  final int depth;

  /**
   * Give an position and internal coordinates that should be converted to exact global coordinates.
   */
  public ExactPosition(Position pos, double x, double y) {
    this.depth = pos.depth;
    this.x = pos.point.x * WorldValues.BLOCK_SIZE + x;
    this.y = pos.point.y * WorldValues.BLOCK_SIZE - y;
  }

  /*
   * Auto generated equals and hash code.
   */
  @Override
  public int hashCode() {
    int hash = 3;
    hash =
        23 * hash
            + (int) (Double.doubleToLongBits(this.x) ^ (Double.doubleToLongBits(this.x) >>> 32));
    hash =
        23 * hash
            + (int) (Double.doubleToLongBits(this.y) ^ (Double.doubleToLongBits(this.y) >>> 32));
    hash = 23 * hash + this.depth;
    return hash;
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    final ExactPosition other = (ExactPosition) obj;
    if (Double.doubleToLongBits(this.x) != Double.doubleToLongBits(other.x)) {
      return false;
    }
    if (Double.doubleToLongBits(this.y) != Double.doubleToLongBits(other.y)) {
      return false;
    }
    if (this.depth != other.depth) {
      return false;
    }
    return true;
  }
}
